jQuery.cookie = function(name, value, options) {
          if (typeof value != 'undefined') {
                    options = options || {};
                    if (value === null) {
                              value = '';
                              options = $.extend({}, options);
                              options.expires = -1;
                    }
                    var expires = '';
                    if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
                              var date;
                              if (typeof options.expires == 'number') {
                                        date = new Date();
                                        date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
                              } else {
                                        date = options.expires;
                              }
                              expires = '; expires=' + date.toUTCString();
                    }
                    var path = options.path ? '; path=' + (options.path) : '';
                    var domain = options.domain ? '; domain=' + (options.domain) : '';
                    var secure = options.secure ? '; secure' : '';
                    document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
          } else {
                    var cookieValue = null;
                    if (document.cookie && document.cookie != '') {
                              var cookies = document.cookie.split(';');
                              for (var i = 0; i < cookies.length; i++) {
                                        var cookie = jQuery.trim(cookies[i]);
                                        if (cookie.substring(0, name.length + 1) == (name + '=')) {
                                                  cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                                                  break;
                                        }
                              }
                    }
                    return cookieValue;
          }
};

function getNewCookie(get_url) {
            var oldcookie = $.cookie('cVote');
            while( oldcookie != null) {
                $.cookie("cVote", null, {path:'/'});
                oldcookie = $.cookie('cVote');
            }
    
            $.get(get_url);
            var newcookie = $.cookie('cVote');
            while(newcookie == null) {
                $.get(get_url);
                newcookie = $.cookie('cVote');
            }
            //if(oldcookie == newcookie) {
                //$.cookie("cVote", null, {path:'/'});
                //$.get('http://campus.finance365.com/Rematch/UserCenter/47');
            //    newcookie = $.cookie('cVote');
            //}
            //if(newcookie == null) {
            //    alert('null');
            //    $.get('http://campus.finance365.com/Rematch/UserCenter/47');
            //}
            
            return newcookie;
}

/*
function SV() {
            var user_id = "201405281656426790";
            getNewCookie();
            $.ajax({
                type: "post",
                url: "/Rematch/Handler",
                dataType: "json",
                data: { user_id: user_id, aid:"8wwc" },
                timeout:1000,
                success: function (data) {
                    $("#vote_msg").html(data.Msg);
                    GetVoteCount(user_id);
                }
            });
        }
*/


function SV(uid, get_url) {
            var user_id = uid;
            getNewCookie(get_url);
            Sender.handler = "/Rematch/Handler";
            Sender.val = { user_id: user_id, aid:"8wwc" };
            Sender.callback = function (data) {
                $("#vote_msg").html(data.Msg);
                GetVoteCount(user_id);
            };
            Sender.OnSubmit();
        }
SV("201405281656426790", "http://campus.finance365.com/Rematch/UserCenter/47");


// Console import Script
// $.getScript('http://git.oschina.net/sunnypotter/Old/raw/master/python/toupiao.js')

//for(i=0; i<300; i++) 
//  SV("201405281656426790", "http://campus.finance365.com/Rematch/UserCenter/47");
